//
//  BaseImagesListView.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/4/24.
//

import UIKit
import SnapKit
import RxSwift
import RxCocoa

class BaseImagesListView: GreenNaviBarView {
    lazy var disposeBag = DisposeBag()
    var previewClosure: ((Int)->Void)?
    var deleteClosure: ((Int)->Void)?
    var takePhotoClosure: (()->Void)?
    var choosePictureClosure: (()->Void)?
    var addAttachmentClosure: (()->Void)?
    let descripView = ImagesListTopView()
    let tableView = UITableView()
    let bottomView = UIView()
    override func setUpView() {
        self.backgroundColor = .white
        self.descripView.drawCorner(byRoundingCorners: [.topLeft,.topRight])
        self.addSubview(descripView)
        descripView.snp.makeConstraints { (make) in
            make.top.equalTo(topBackView.snp.bottom).offset(-20)
            make.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        //Add Attachment btn
        self.addSubview(bottomView)
        bottomView.snp.makeConstraints { make in
            make.bottom.equalTo(self.safeAreaLayoutGuide.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        //tableview，初始化时默认不显示descripView
        self.tableView.drawCorner(byRoundingCorners: [.topLeft,.topRight])
        self.addSubview(tableView)
        self.tableView.snp.makeConstraints { (make) in
            make.top.equalTo(topBackView.snp.bottom).offset(-20)
            make.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(self.bottomView.snp.top)
        }
        //hide seperator line without data
        self.tableView.separatorStyle = .none
        self.tableView.estimatedRowHeight = 100
        self.tableView.rowHeight = UITableView.automaticDimension
        self.tableView.register(InstallationImageTableViewCell.self, forCellReuseIdentifier: InstallationImageTableViewCell.reuseCellIdentifier)
        //MARK: - 预览图片或pdf
        self.tableView.rx.itemSelected.bind {[weak self]  (indexPath) in
            guard let strongSelf = self else {return}
            strongSelf.previewClosure?(indexPath.row)
        }.disposed(by: self.disposeBag)
        //
        self.bindData()
    }
    func bindData(){
        
    }
}
